﻿using System;
using GeoAPI.Geometries;
using NetTopologySuite.Operation.Overlay;

namespace HYCodeBase.TopologySuite
{
	public abstract class BaseBooleanOperater
	{
		protected bool TryGetOperateResult(IGeometry inputGeometryOne, IGeometry inputGemetryTwo, BooleanOperatorKindEnum useKind, out IGeometry results)
		{
			return BaseBooleanOperater.TryGetOperateResultStatic(inputGeometryOne, inputGemetryTwo, useKind, out results);
		}

		internal static bool TryGetOperateResultStatic(IGeometry inputGeometryOne, IGeometry inputGemetryTwo, BooleanOperatorKindEnum useKind, out IGeometry results)
		{
			results = null;
			if (inputGeometryOne == null || inputGemetryTwo == null)
			{
				return false;
			}
			bool result;
			try
			{
				new OverlayOp(inputGeometryOne, inputGemetryTwo);
				SpatialFunction opCode = (SpatialFunction)(useKind + 1);
				results = OverlayOp.Overlay(inputGeometryOne, inputGemetryTwo, opCode);
				if (results == null)
				{
					result = false;
				}
				else
				{
					result = true;
				}
			}
			catch (Exception)
			{
				result = false;
			}
			return result;
		}
	}
}
